<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>美滴滴</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link type="text/css" rel="stylesheet" media="screen" href="__FONT__/css/style.css{$JSDEBUG}"/>
    <link type="text/css" rel="stylesheet" media="screen" href="__FONT__/css/media.css{$JSDEBUG}"/>
    <script type="text/javascript" src="__FONT__/js/jquery-1.9.1.min.js{$JSDEBUG}"></script>
    <style>
    	body{padding-top: 0px;}
    </style>
</head>
<body style="background:#fff;">
	<form action="{:U('/User/bind')}" method="post" id="bindForm">
		<input type="hidden" name="redirect" value="{$redirect}">
 	<section>
      <div class="login">
      	<h1><img src="__FONT__/images/loginlogo.png"></h1>
        <ul>
          <li><input type="tel" name="phone" id="phone" maxlength="11" placeholder="请输入会员手机号码" class="phone" ></li>
          <li>
              <input type="tel" name="code" id="code" placeholder="输入您获取到的验证码" class="code">
          </li>
          <li>
              <input type="button" class="submit" id="huoqu" value="获取验证码">
              <div  class="time" style="display:none;"><span>60</span>s重获</div>
          </li>
          <li><input type="button" value="立即登陆" class="dllogin" ></li>  <!--填写完addClass("addbg")-->
        </ul>
      </div> 
	</section>
	</form>
<script>
function abc() {
    $('#huoqu').hide();
    $('.time').show();
    var sec = $(".time span").text();
    $(".time span").text(--sec);
    if (sec >= 1) {
        setTimeout("abc();", 1000);
    } else {
        $('#huoqu').show();
        $('.time').hide();
        $(".time span").text(60);
    }
    return false;
}

var getCode = false, sendCode = false;
function getValidCode() {
	$("#huoqu").attr('disabled', true);
	$.ajax({
		url: '{:U("/User/sendCode")}',
		data: {phone: $('input[name="phone"]').val()},
		dataType: 'json',
		type: 'GET',
		success: function (result) {
			$("#huoqu").removeAttr('disabled');
			getCode = false;
			if (result.status) {
				sendCode = true;
				abc();
			} else {
				sendCode = false;
				alert('获取验证码失败！请重试');
			}
		},
		error: function () {
			$("#huoqu").removeAttr('disabled');
			getCode = false;
			sendCode = false;
			alert('获取验证码失败！请重试');
		}
	});
}

$(function () {
	var valid=false;
	$("#phone,#code").keyup(function () {
		var phone = $('input[name="phone"]').val();
		var reg=/^0?1[3|4|5|7|8][0-9]\d{8}$/;
		
		if ($.trim(phone) == '' || !reg.test(phone)) {
			$('.dllogin,#huoqu').removeClass('addbg');
			return false;
		}
		
		$('#huoqu').addClass('addbg');
		
		var code = $('input[name="code"]').val();
		var reg=/^\d{6}$/;
		if (!reg.test(code)) {
			$('.dllogin').removeClass('addbg');
			return false;
		}
		
		$('.dllogin').addClass('addbg');
	});
	
	var submitUserInfo;
	$(".dllogin").click(function () {
		if (submitUserInfo && submitUserInfo.state() == 'pending') {
			return false;
		}
		
		var phone = $('input[name="phone"]').val();
		var reg=/^\d{11}$/;
		if (!reg.test(phone)) {
			alert('输入的手机号码不正确');
			return false;
		}
		
		var code = $('input[name="code"]').val();
		var reg=/^\d{6}$/;
		if (!reg.test(code)) {
			alert('输入的验证码格式不正确');
			return false;
		}
		
		var form = $('form').get(0);
		subming = $.ajax({
			url: form.action,
			data: $(form).serialize(),
			type: 'post',
			dataType: 'json',
			success: function (result) {
				if (result.status == '1') {
					window.location.href = result.redirect;
				} else {
					alert(result.message);
					return false;
				}
			},
			error: function (e, s, d) {
				alert('登录失败');
			}
		});
		return true;
	});
	
	$("#huoqu").click(function () {
		if (getCode) {
			alert('正在获取，请等待');
		}
		
		var phone = $('input[name="phone"]').val();
		if ($.trim(phone) == '') {
			$('.dllogin,#huoqu').removeClass('addbg');
			alert('请输入手机号码');
			return false;
		}
		
		var reg=/^0?1[3|4|5|7|8][0-9]\d{8}$/;
		if (!reg.test(phone)) {
			$('.dllogin,#huoqu').removeClass('addbg');
			alert('输入的手机号码不正确');
			return false;
		}
		
		getCode =true;
		getValidCode();
	});
});
</script>
</body>
</html>